var m_callback;
var m_cticlient;
var c_cti = "m7edb";

function createIframe(id) {
	try {
		var iframe = document.createElement('iframe');
	    iframe.name = id;
	    iframe.id = id;
	    return iframe;
	} catch (err) {
	  	console.log(err.stack);
	}
};

function createctiiframe(src) {
	var iframe = document.getElementById("cti");
	if (!iframe) {
		console.log('create cti Iframe for ' + src);
		var iframe = createIframe('cti');
		iframe.src = src;
		iframe.style='visibility:hidden;display:none;';
		iframe.width ='0';
		iframe.height='0';
		document.body.appendChild(iframe);
	} else {
		console.log('use cti Iframe for ' + src);
		iframe.src = src;
	}
};

function iframeonload(cticlient) {
	console.log('iframeonload');
	//debugger;
	m_cticlient = cticlient;
	if (m_callback) {
		m_callback(m_cticlient);
	}
}
	
define([], function(){
	//createctiiframe();
	var CTIClientFactory = {
		getCTIClient: function(callback) {
            createctiiframe($E.softphoneBasePath + "/softphone/" + c_cti + "/" + c_cti + "page.html");
			m_callback = callback;
    	}
    };
	return CTIClientFactory;
})